from Products.CMFCore.utils import getToolByName
from Products.PythonScripts.standard import html_quote
from Products.CMFPlone.utils import base_hasattr

request = context.REQUEST

descDict = {}

if base_hasattr(request, 'username') and base_hasattr(request, 'password') and base_hasattr(request, 'email'):
    username = request.get('username', '')
    password = request.get('password', '')
    email=request.get('email','')
    roles=('Member',)
    registration = getToolByName(context, 'portal_registration')
    if not registration.isMemberIdAllowed(username):
        descDict['Status'] = 'Error'
        descDict['Message'] = 'NameExisted'
    elif len(password)<6:
        descDict['Status'] = 'Error'
        descDict['Message'] = 'Password NotExisted OR TooShort'
    elif not registration.isValidEmail(email):
        descDict['Status']  = 'Error'
        descDict['Message'] = 'EmailInvalid'
    else:
        try:
            properties = {'email': email,}
            registration.addMember(username, password,('Member',), properties,request)
            descDict['Status']= 'Success'
            descDict['Message']= 'NoMessage'
        except:
            descDict['Status']= 'Exception'
            descDict['Message'] = '%s:%s' % (username,password)
else:
    descDict['Status'] = 'Error'
    descDict['Message'] = 'LackData'

result = "{\"Status\":\"%s\",\"Message\":\"%s\"}" % (descDict['Status'],descDict['Message'])

return result
